package pe.com.certicom.moviles.model.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import pe.com.certicom.moviles.model.beans.Articulo;
import pe.com.certicom.moviles.model.beans.ArticuloExample;
import pe.com.certicom.moviles.model.beans.PeriodoFacturacion;
import pe.com.certicom.moviles.model.beans.ReporteBitacora;
import pe.com.certicom.moviles.model.beans.ReporteDetalleBitacora;
import pe.com.certicom.moviles.model.beans.ReporteEstado;

import com.ibatis.sqlmap.client.SqlMapClient;


@Repository
public class ArticuloDAOImpl extends SqlMapClientDaoSupport implements ArticuloDAO {

	
	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public ArticuloDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int countByExample(ArticuloExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"articulo.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int deleteByExample(ArticuloExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"articulo.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int deleteByPrimaryKey(Long idArticulo) {
		Articulo key = new Articulo();
		key.setIdArticulo(idArticulo);
		int rows = getSqlMapClientTemplate().delete(
				"articulo.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public void insert(Articulo record) {
		getSqlMapClientTemplate().insert("articulo.ibatorgenerated_insert",
				record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public void insertSelective(Articulo record) {
		getSqlMapClientTemplate().insert(
				"articulo.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	@SuppressWarnings("unchecked")
	public List<Articulo> selectByExample(ArticuloExample example) {
		List<Articulo> list = getSqlMapClientTemplate().queryForList(
				"articulo.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public Articulo selectByPrimaryKey(Long idArticulo) {
		Articulo key = new Articulo();
		key.setIdArticulo(idArticulo);
		Articulo record = (Articulo) getSqlMapClientTemplate().queryForObject(
				"articulo.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int updateByExampleSelective(Articulo record, ArticuloExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"articulo.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int updateByExample(Articulo record, ArticuloExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"articulo.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int updateByPrimaryKeySelective(Articulo record) {
		int rows = getSqlMapClientTemplate().update(
				"articulo.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	public int updateByPrimaryKey(Articulo record) {
		int rows = getSqlMapClientTemplate().update(
				"articulo.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table articulo
	 * @ibatorgenerated  Tue May 28 14:57:18 COT 2013
	 */
	private static class UpdateByExampleParms extends ArticuloExample {
		private Object record;

		public UpdateByExampleParms(Object record, ArticuloExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@Autowired
	public void createSqlMapClient(SqlMapClient sqlMapClient){
	   setSqlMapClient(sqlMapClient);
	}
	
    @Override
	public List<Articulo> listarArticulosAsignablesPorOperadorYMarca(String codTipoArticulo, String codOperador, Long idMarca) {
		Map<String,Object> parametros = new HashMap<String,Object>();
		parametros.put("codTipoArticulo",codTipoArticulo);
		parametros.put("codOperador",codOperador);
		parametros.put("idMarca",idMarca);
		List<Articulo> list = getSqlMapClientTemplate().queryForList("articulo.listarArticulosAsignablesPorOperadorYMarca", parametros);
        return list;
	}

	@Override
	public List<Articulo> listarArticulosAReponerPorOperadorYMarca(String codTipoArticulo, String codOperador, Long idMarca) {
		Map<String,Object> parametros = new HashMap<String,Object>();
		parametros.put("codTipoArticulo",codTipoArticulo);
		parametros.put("codOperador",codOperador);
		parametros.put("idMarca",idMarca);
		List<Articulo> list = getSqlMapClientTemplate().queryForList("articulo.listarArticulosAReponerPorOperadorYMarca", parametros);
        return list;
	}

	@Override
	public List<Articulo> listarArticulosEnPerdidaPorOperadorYMarca(String codTipoArticulo, String codOperador, Long idMarca) {
		Map<String,Object> parametros = new HashMap<String,Object>();
		parametros.put("codTipoArticulo",codTipoArticulo);
		parametros.put("codOperador",codOperador);
		parametros.put("idMarca",idMarca);
		List<Articulo> list = getSqlMapClientTemplate().queryForList("articulo.listarArticulosEnPerdidaPorOperadorYMarca", parametros);
        return list;
	}

	@Override
	public List<ReporteEstado> generarReporteEstado(Map<String, Object> parametros) {
		List<ReporteEstado> list = getSqlMapClientTemplate().queryForList("articulo.generarReporteEstado", parametros);
        return list;
	}

	@Override
	public List<ReporteEstado> generarReporteMovimientos(
			Map<String, Object> parametros) {
		List<ReporteEstado> list = getSqlMapClientTemplate().queryForList("articulo.generarReporteMovimientos", parametros);
        return list;
	}

	@Override
	public List<ReporteBitacora> generarReporteBitacora(
			Map<String, Object> parametros) {
		List<ReporteBitacora> list = getSqlMapClientTemplate().queryForList("articulo.generarReporteBitacora", parametros);
        return list;
	}

	@Override
	public List<ReporteDetalleBitacora> generarReporteDetalleBitacora(
			Map<String, Object> parametros) {
		List<ReporteDetalleBitacora> list = getSqlMapClientTemplate().queryForList("articulo.generarReporteDetalleBitacora", parametros);
        return list;
	}

	@Override
	public List<Articulo> listarEquiposFacturables(PeriodoFacturacion periodoFacturacion) {
		List<Articulo> list = getSqlMapClientTemplate().queryForList("articulo.listarEquiposFacturables", periodoFacturacion);
        return list;
	}

	@Override
	public int updateEquiposFacturables(PeriodoFacturacion periodoFacturacion) {
		int rows = getSqlMapClientTemplate().update(
				"articulo.updateEquiposFacturables", periodoFacturacion);
		return rows;
	}
}